package util;

import java.io.*;
import java.net.URL;

// loads shaders from file
public class ShaderLoader {
	public ShaderLoader(URL vsFname, URL gsName, URL fsFname)
			throws IOException {
		URL[] fnames = { vsFname, gsName, fsFname };
		for (int i = 0; i < fnames.length; ++i) {
			if (fnames[i] == null) {
				continue;
			}

			StringBuilder sb = new StringBuilder();
			BufferedReader r = new BufferedReader(new InputStreamReader(fnames[i].openStream()));
			char[] buf = new char[1024];
			int amount;
			while ((amount = r.read(buf)) >= 0) {
				sb.append(buf, 0, amount);
			}
			sources[i] = sb.toString();
			r.close();
		}
	}

	private String[] sources = new String[3];

	public String getVertexShaderSource() {
		return sources[0];
	}

	public String getGeometryShaderSource() {
		return sources[1];
	}

	public String getFragmentShaderSource() {
		return sources[2];
	}
}